move floor to C++20 (#1206)
authortsteven4 <13596209+tsteven4@users.noreply.github.com>
Fri, 9 Aug 2024 23:02:46 +0000 (17:02 -0600)
committerGitHub <noreply@github.com>
Fri, 9 Aug 2024 23:02:46 +0000 (17:02 -0600)
* move floor to c++20

drop Visual Studio 2017.
use default member intializers for bit-fields.

* use more bit-field default initializers

* try Xcod 14.3.1 on macOS 13.

* echo clang version

which can be useful with homebrew fails_with

* use std::numbers

* finish eradication of M_PI.

* fix some whitespace

17 files changed:
CMakeLists.txt
defs.h
garmin.cc
garmin_fs.h
geocache.h
googletakeout.h
grtcirc.cc
grtcirc.h
humminbird.cc
jeeps/gpsmath.h
lowranceusr.cc
lowranceusr.h
main.cc
precompiled_headers.h
skytraq.cc
src/core/nvector.cc
src/core/nvector.h

index 55ac322d9b623da2e4dd9503b0a5f517d2e87a78..2193b851b061d1f8d51d99e568b2ee46209c0fae 100644 (file)
@@ -6,7 +6,7 @@ include(CheckIncludeFile)
 include(gbversion.cmake)
 project(gpsbabel LANGUAGES C CXX VERSION ${GB.VERSION})
 
-set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD 20)
 set(CMAKE_CXX_STANDARD_REQUIRED True)
 
 # Do this after we set up common variables but before creating other
diff --git a/defs.h b/defs.h
index 85465104c105d437062ca8840068bbe78e268d3d..df3e8c3aaffc0303e447d785aa99f35d91d69f68 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -19,7 +19,6 @@
 #ifndef DEFS_H_INCLUDED_
 #define DEFS_H_INCLUDED_
 
-#include <cmath>                     // for M_PI
 #include <cstddef>                   // for NULL, nullptr_t, size_t
 #include <cstdint>                   // for int32_t, uint32_t
 #include <cstdio>                    // for NULL, fprintf, FILE, stdout
@@ -36,7 +35,6 @@
 #include <QString>                   // for QString
 #include <QStringView>               // for QStringView
 #include <QTextCodec>                // for QTextCodec
-#include <QVector>                   // for QVector
 #include <Qt>                        // for CaseInsensitive
 #include <QtGlobal>                  // for QForeachContainer, qMakeForeachContainer, foreach, qint64
 
 #define CSTR(qstr) ((qstr).toUtf8().constData())
 #define CSTRc(qstr) ((qstr).toLatin1().constData())
 
-/*
- * Amazingly, this constant is not specified in the standard...
- */
-#ifndef M_PI
-#  define M_PI 3.14159265358979323846
-#endif
 
 /*
  * The constants marked "exact in decimal notation" may be more accurately
@@ -235,17 +227,11 @@ public:
 class wp_flags
 {
 public:
-  wp_flags() :
-    shortname_is_synthetic(0),
-    fmt_use(0),
-    is_split(0),
-    new_trkseg(0),
-    marked_for_deletion(0) {}
-  unsigned int shortname_is_synthetic:1;
-  unsigned int fmt_use:2;                      /* lightweight "extra data" */
-  unsigned int is_split:1;             /* the waypoint represents a split */
-  unsigned int new_trkseg:1;           /* True if first in new trkseg. */
-  unsigned int marked_for_deletion:1;          /* True if schedulded for deletion. */
+  unsigned int shortname_is_synthetic:1{0};
+  unsigned int fmt_use:2{0};                /* lightweight "extra data" */
+  unsigned int is_split:1{0};               /* the waypoint represents a split */
+  unsigned int new_trkseg:1{0};             /* True if first in new trkseg. */
+  unsigned int marked_for_deletion:1{0};    /* True if schedulded for deletion. */
 };
 
 /*
@@ -275,21 +261,14 @@ private:
   class op_flags
   {
   public:
-    op_flags() :
-      temperature(false),
-      proximity(false),
-      course(false),
-      speed(false),
-      geoidheight(false),
-      depth(false) {}
-    bool temperature:1;                /* temperature field is set */
-    bool proximity:1;          /* proximity field is set */
-    bool course:1;                     /* course field is set */
-    bool speed:1;                      /* speed field is set */
-    bool geoidheight:1;        /* geoidheight field is set */
-    bool depth:1;                      /* depth field is set */
+    bool temperature:1{false}; /* temperature field is set */
+    bool proximity:1{false};   /* proximity field is set */
+    bool course:1{false};      /* course field is set */
+    bool speed:1{false};       /* speed field is set */
+    bool geoidheight:1{false}; /* geoidheight field is set */
+    bool depth:1{false};       /* depth field is set */
     /* !ToDo!
-    unsigned int altitude:1;           /+ altitude field is set +/
+    unsigned int altitude:1{false}; /+ altitude field is set +/
     ... and hdop,pdop,vdop,fix,sat,heartrate,cadence,power,
     odometer_distance
     */
index d676e33df6af80de512421574fa4873516ddccdf..7c20fc836228b09e44ed1d52d76637305238ae45 100644 (file)
--- a/garmin.cc
+++ b/garmin.cc
@@ -1010,7 +1010,7 @@ GarminFormat::route_write()
   for (int i = 0; i < n; i++) {
     GPS_Way_Del(&tx_routelist[i]);
   }
-  
+
   xfree(tx_routelist);
 }
 
index 00c16074b875dd7600c46847b9eb5a96d8223d34..5ed17e9ae50b8cc06d7ee5475ae1ed11fa2d48c0 100644 (file)
@@ -50,48 +50,26 @@ struct garmin_ilink_t {
 
 struct garmin_fs_flags_t {
 public:
-  garmin_fs_flags_t() :
-  icon(0),
-  wpt_class(0),
-  display(0),
-  category(0),
-  city(0),
-  state(0),
-  facility(0),
-  cc(0),
-  cross_road(0),
-  addr(0),
-  country(0),
-  phone_nr(0),
-  phone_nr2(0),
-  fax_nr(0),
-  postal_code(0),
-  email(0),
-  duration(0)
-#ifdef GMSD_EXPERIMENTAL
-  , subclass(0)
-#endif
-  {}
-
-  unsigned int icon:1;
-  unsigned int wpt_class:1;
-  unsigned int display:1;
-  unsigned int category:1;
-  unsigned int city:1;
-  unsigned int state:1;
-  unsigned int facility:1;
-  unsigned int cc:1;
-  unsigned int cross_road:1;
-  unsigned int addr:1;
-  unsigned int country:1;
-  unsigned int phone_nr:1;
-  unsigned int phone_nr2:1;
-  unsigned int fax_nr:1;
-  unsigned int postal_code:1;
-  unsigned int email:1;
-  unsigned int duration:1;
+
+  unsigned int icon:1{0};
+  unsigned int wpt_class:1{0};
+  unsigned int display:1{0};
+  unsigned int category:1{0};
+  unsigned int city:1{0};
+  unsigned int state:1{0};
+  unsigned int facility:1{0};
+  unsigned int cc:1{0};
+  unsigned int cross_road:1{0};
+  unsigned int addr:1{0};
+  unsigned int country:1{0};
+  unsigned int phone_nr:1{0};
+  unsigned int phone_nr2:1{0};
+  unsigned int fax_nr:1{0};
+  unsigned int postal_code:1{0};
+  unsigned int email:1{0};
+  unsigned int duration:1{0};
 #ifdef GMSD_EXPERIMENTAL
-  unsigned int subclass:1;
+  unsigned int subclass:1{0};
 #endif
 };
 
index e53cc7193efa0803bf090159d3339236b99837d3..a2d73d2945d9c8e3862211a3ae359e883b7b0fc3 100644 (file)
@@ -79,22 +79,6 @@ public:
     QString utf_string;
   };
 
-  /* Special Member Functions */
-
-  Geocache() :
-    id(0),
-    type(type_t::gt_unknown),
-    container(container_t::gc_unknown),
-    diff(0),
-    terr(0),
-    is_archived(status_t::gs_unknown),
-    is_available(status_t::gs_unknown),
-    is_memberonly(status_t::gs_unknown),
-    has_customcoords(status_t::gs_unknown),
-    placer_id(0),
-    favorite_points(0)
-  {}
-
   /* Member Functions */
 
   void set_type(const QString& type_name);
@@ -105,22 +89,22 @@ public:
 
   /* Data Members */
 
-  long long id; /* The decimal cache number */
-  type_t type:5;
-  container_t container:4;
-  unsigned int diff:6; /* (multiplied by ten internally) */
-  unsigned int terr:6; /* (likewise) */
-  status_t is_archived:2;
-  status_t is_available:2;
-  status_t is_memberonly:2;
-  status_t has_customcoords:2;
+  long long id{0}; /* The decimal cache number */
+  type_t type:5{type_t::gt_unknown};
+  container_t container:4{container_t::gc_unknown};
+  unsigned int diff:6{0}; /* (multiplied by ten internally) */
+  unsigned int terr:6{0}; /* (likewise) */
+  status_t is_archived:2{status_t::gs_unknown};
+  status_t is_available:2{status_t::gs_unknown};
+  status_t is_memberonly:2{status_t::gs_unknown};
+  status_t has_customcoords:2{status_t::gs_unknown};
   gpsbabel::DateTime last_found;
   QString placer; /* Placer name */
-  int placer_id; /* Placer id */
+  int placer_id{0}; /* Placer id */
   QString hint; /* all these UTF8, XML entities removed, May be not HTML. */
   UtfString desc_short;
   UtfString desc_long;
-  int favorite_points;
+  int favorite_points{0};
   QString personal_note;
 
 private:
index 4754366cab73358510082db96c26f1f52656b493..3d805562a1e02dc02e415c7afa212fcc0868a33a 100644 (file)
@@ -120,7 +120,7 @@ private:
   };
 
   /* Member Functions */
+
   static void takeout_fatal(const QString& message);
   static void takeout_warning(const QString& message);
   static Waypoint* takeout_waypoint(int lat_e7, int lon_e7, const QString* shortname, const QString* description, const QString* start_str);
index 94ea141f9c5821a21f80c34276334f5c3f1f7a4b..b4d80d7c0c1cbad79a2771e441cda219546b30e8 100644 (file)
@@ -26,6 +26,7 @@
 #include <cerrno>
 #include <cmath>
 #include <cstdio>
+#include <numbers>
 #include <tuple>
 
 static constexpr double EARTH_RAD = 6378137.0;
@@ -276,7 +277,7 @@ double linedistprj(double lat1, double lon1,
       }
     } else {
       /* lp is 0 when 3 is 90 degrees from the great circle */
-      return M_PI / 2;
+      return std::numbers::pi / 2;
     }
   } else {
     /* la is 0 when 1 and 2 are either the same point or 180 degrees apart */
index 70641f183526d25f1621e8de789fe368cd67f255..821eccef48860ccabed8cfaa256dd72ccdf7368a 100644 (file)
--- a/grtcirc.h
+++ b/grtcirc.h
@@ -22,6 +22,8 @@
 #ifndef GRTCIRC_H
 #define GRTCIRC_H
 
+#include <numbers>  // for inv_pi
+
 double gcdist(double lat1, double lon1, double lat2, double lon2);
 double heading(double lat1, double lon1, double lat2, double lon2);
 double heading_true_degrees(double lat1, double lon1, double lat2, double lon2);
@@ -45,7 +47,7 @@ void linepart(double lat1, double lon1,
               double* reslat, double* reslon);
 
 /* Degrees to radians */
-constexpr double kDegreesPerRadian = 180.0 / M_PI;
+constexpr double kDegreesPerRadian = 180.0 * std::numbers::inv_pi;
 constexpr double DEG(double x) { return x * kDegreesPerRadian; }
 
 /* Radians to degrees */
index ea3f2f3a82eae52b9b4a5259b0db2a5268ed281e..d4a597b26ff4b5098ec255e40833c57c7dcc7a47 100644 (file)
 #include <Qt>                   // for CaseInsensitive
 #include <QtGlobal>             // for qRound
 
-#include <cmath>                // for atan, tan, M_PI, log, sinh
+#include <cmath>                // for atan, tan, log, sinh
 #include <cstdio>               // for snprintf, SEEK_SET
 #include <cstring>              // for strncpy, memcpy, memset
+#include <numbers>              // for inv_pi, pi
 
 #include "defs.h"               // for Waypoint, be_read32, be_read16, be_write32, fatal, xfree, be_write16, route_head, xcalloc, track_add_wpt, xstrndup
 #include "mkshort.h"            // for MakeShort
@@ -61,7 +62,7 @@ Still, they're useful in the code as a plain signature.
 #define WPT_MAGIC2             0x02030024L // New for 2013.  No visible diff?!
 #define RTE_MAGIC              0x03030088L
 
-#define EAST_SCALE             20038297.0 /* this is i1924_equ_axis*M_PI */
+#define EAST_SCALE             20038297.0 /* this is i1924_equ_axis*pi */
 #define i1924_equ_axis         6378388.0
 #define i1924_polar_axis       6356911.946
 
@@ -173,9 +174,9 @@ HumminbirdBase::geodetic_to_geocentric_hwr(const double gd_lat)
 {
   constexpr double cos_ae = 0.9966349016452;
   constexpr double cos2_ae = cos_ae * cos_ae;
-  const double gdr = gd_lat *M_PI / 180.0;
+  const double gdr = gd_lat * std::numbers::pi / 180.0;
 
-  return atan(cos2_ae * tan(gdr)) * 180.0/M_PI;
+  return atan(cos2_ae * tan(gdr)) * 180.0 * std::numbers::inv_pi;
 }
 
 /* Takes a latitude in degrees,
@@ -185,9 +186,9 @@ HumminbirdBase::geocentric_to_geodetic_hwr(const double gc_lat)
 {
   constexpr double cos_ae = 0.9966349016452;
   constexpr double cos2_ae = cos_ae * cos_ae;
-  const double gcr = gc_lat *M_PI / 180.0;
+  const double gcr = gc_lat * std::numbers::pi / 180.0;
 
-  return atan(tan(gcr)/cos2_ae) * 180.0/M_PI;
+  return atan(tan(gcr)/cos2_ae) * 180.0 * std::numbers::inv_pi;
 }
 
 /* Takes a projected "north" value, returns latitude in degrees. */
@@ -196,15 +197,15 @@ HumminbirdBase::gudermannian_i1924(const double x)
 {
   const double norm_x = x/i1924_equ_axis;
 
-  return atan(sinh(norm_x)) * 180.0/M_PI;
+  return atan(sinh(norm_x)) * 180.0 * std::numbers::inv_pi;
 }
 
 /* Takes latitude in degrees, returns projected "north" value. */
 double
 HumminbirdBase::inverse_gudermannian_i1924(const double x)
 {
-  const double x_r = x/180.0 * M_PI;
-  const double guder = log(tan(M_PI/4.0 + x_r/2.0));
+  const double x_r = x/180.0 * std::numbers::pi;
+  const double guder = log(tan(std::numbers::pi/4.0 + x_r/2.0));
 
   return guder * i1924_equ_axis;
 }
index e4adcfb0e21c47e02a1c934174d555a3da7326ad..dadd2863fe8a5e131481256d45c52280fd40ffff 100644 (file)
@@ -3,11 +3,12 @@
 
 #include <cstdint>   // for int32_t
 #include <ctime>     // for time_t
+#include <numbers>   // for pi
 
 #include <QString>   // for QString
 
 
-constexpr double GPS_PI = 3.14159265358979323846;
+constexpr double GPS_PI = std::numbers::pi;
 
 
 double GPS_Math_Deg_To_Rad(double v);
index 92f533a18263a3292d89ecfe679cd4f8583eee15..8e38e6f8a0dd945fb2795881feacf9147402e656 100644 (file)
 #include "lowranceusr.h"
 
 #include <cinttypes>            // for PRId64
-#include <cmath>                // for M_PI, round, atan, exp, log, tan
+#include <cmath>                // for round, atan, exp, log, tan
 #include <cstdio>               // for printf, sprintf, SEEK_CUR
 #include <cstdint>              // for int64_t
 #include <cstdlib>              // for abs
 #include <cstring>              // for strcmp, strlen
+#include <numbers>              // for pi
 #include <utility>              // for as_const
 
 #include <QByteArray>           // for QByteArray
@@ -377,7 +378,7 @@ LowranceusrFormat::lon_mm_to_deg(double x)
 double
 LowranceusrFormat::lat_mm_to_deg(double x)
 {
-  return (2.0 * atan(exp(x / SEMIMINOR)) - M_PI / 2.0) / DEGREESTORADIANS;
+  return (2.0 * atan(exp(x / SEMIMINOR)) - std::numbers::pi / 2.0) / DEGREESTORADIANS;
 }
 
 long
@@ -389,7 +390,7 @@ LowranceusrFormat::lon_deg_to_mm(double x)
 long
 LowranceusrFormat::lat_deg_to_mm(double x)
 {
-  return round(SEMIMINOR * log(tan((x * DEGREESTORADIANS + M_PI / 2.0) / 2.0)));
+  return round(SEMIMINOR * log(tan((x * DEGREESTORADIANS + std::numbers::pi / 2.0) / 2.0)));
 }
 
 void
index 98c21ef69437acf16d110ce5f543732da40d30ca..ee54fc46d182faa6138deb5c48445e1f8903c15e 100644 (file)
@@ -87,8 +87,9 @@
 #ifndef LOWRANCEUSR_H_INCLUDED_
 #define LOWRANCEUSR_H_INCLUDED_
 
-#include <cmath>                // for M_PI, round, atan, exp, log, tan
+#include <cmath>                // for round, atan, exp, log, tan
 #include <cstdint>              // for int64_t
+#include <numbers>              // for pi
 
 #include <QList>                // for QList
 #include <QString>              // for QString
@@ -378,7 +379,7 @@ private:
 
   static constexpr int MAXUSRSTRINGSIZE = 256;
   static constexpr double SEMIMINOR = 6356752.3142;
-  static constexpr double DEGREESTORADIANS = M_PI/180.0;
+  static constexpr double DEGREESTORADIANS = std::numbers::pi/180.0;
   static constexpr int MAX_TRAIL_POINTS = 9999;
   static constexpr double UNKNOWN_USR_ALTITUDE = METERS_TO_FEET(-10000); /* -10000ft is how the unit stores unknown */
   static constexpr int64_t base_time_secs = 946706400; /* Jan 1, 2000 00:00:00 */
diff --git a/main.cc b/main.cc
index 7667c1af9e46576deb85912716f41d3ff64b6f42..9e62fde5212b7d3f0c7c39e271e88d4652718af5 100644 (file)
--- a/main.cc
+++ b/main.cc
@@ -742,8 +742,8 @@ main(int argc, char* argv[])
 #error This version of Qt is not supported.
 #endif
 
-#if defined(_MSC_VER) && (_MSC_VER < 1920) /* MSVC 2017 or earlier */
-#error MSVC 2017 and earlier are not supported. Please use MSVC 2019 or MSVC 2022.
+#if defined(_MSC_VER) && (_MSC_VER < 1920) /* Visual Studio 2017 or earlier */
+#error Visual Studio 2017 and earlier are not supported. Please use Visual Studio 2019 or 2022.
 #endif
 
   if constexpr (DEBUG_LOCALE) {
index 47705c84397057c86b28f874073d5308bced5fde..bcf1b63b0b73ffa894a040835c92601a0aa9b6ee 100644 (file)
 
 #if defined __cplusplus
 #include <algorithm>              // for sort, stable_sort
-#include <cmath>                  // for M_PI
 #include <cstdarg>                // for va_list
 #include <cstddef>                // for NULL, nullptr_t, size_t
 #include <cstdint>                // for int32_t, uint32_t
 #include <cstdio>                 // for NULL, fprintf, FILE, stdout
 #include <ctime>                  // for time_t
+#include <numbers>                // for inv_pi, pi
 #include <optional>               // for optional
 #include <utility>                // for move
 
index 180547cbdcd642e7241e53cfa38dc857efacf209..f6df657afd5267a11a2c308187d29040280211ed 100644 (file)
  */
 
 #include <cctype>          // for isprint
-#include <cmath>           // for cos, sin, atan2, pow, sqrt, M_PI
+#include <cmath>           // for cos, sin, atan2, pow, sqrt
 #include <cstdarg>         // for va_end, va_list, va_start
 #include <cstdio>          // for sscanf, snprintf, vprintf, SEEK_SET
 #include <cstdlib>         // for free
 #include <cstring>         // for memset
+#include <numbers>         // for inv_pi, pi
 
 #include <QByteArray>      // for QByteArray
 #include <QChar>           // for QChar
@@ -581,8 +582,8 @@ SkytraqBase::ECEF_to_LLA(double x, double y, long z, double* lat, double* lon, d
   /* height above ellipsoid (in meters): */
   *alt = AP/cos(*lat) - CA/sqrt(1 - CE2 * pow(sin(*lat), 2));
 
-  *lat = *lat /M_PI*180;
-  *lon = *lon /M_PI*180;
+  *lat = *lat * std::numbers::inv_pi * 180;
+  *lon = *lon * std::numbers::inv_pi * 180;
 }
 
 void
@@ -1322,8 +1323,8 @@ void MinihomerFormat::lla2ecef(double lat, double lng, double alt, double* ecef_
   long double a = 6378137.0;
   long double esqr = 6.69437999014e-3;
 
-  long double llat = lat*M_PI/180;
-  long double llng = lng*M_PI/180;
+  long double llat = lat * std::numbers::pi / 180;
+  long double llng = lng * std::numbers::pi / 180;
   long double lalt = alt;
 
   long double s = sin(llat);
index a35efc6917bd7d2253c0595c9955cd395bc85d9f..f6e8ad8940c8d01f5755ee2b11c0db2eb8292548 100644 (file)
 // https://en.wikipedia.org/wiki/N-vector
 // http://www.navlab.net/Publications/A_Nonsingular_Horizontal_Position_Representation.pdf
 
-#include <cfloat>
-#include <cmath>
-#include <cstdio>
-#include <iostream>
-#include <utility>
+#include "src/core/nvector.h"
 
-#include "nvector.h"
-#include "vector3d.h"
+#include <cfloat>               // for DBL_EPSILON
+#include <cmath>                // for sqrt, atan2, cos, nan, sin, cbrt
+#include <utility>              // for pair
+
+#include "src/core/vector3d.h"  // for Vector3D
 
 namespace gpsbabel
 {
@@ -401,7 +400,7 @@ double NVector::crossTrackDistance(const NVector& n_EA_E, const NVector& n_EB_E,
 {
   Vector3D c_E = crossProduct(n_EA_E, n_EB_E).normalize();
   double result = fabs((atan2(crossProduct(c_E, n_EX_E).norm(),
-                              dotProduct(c_E, n_EX_E)) - M_PI/2.0)) * MEAN_EARTH_RADIUS_METERS;
+                              dotProduct(c_E, n_EX_E)) - std::numbers::pi/2.0)) * MEAN_EARTH_RADIUS_METERS;
   return result;
 }
 #else
index 4cd7b820fadd665437c5d97fdd115d68afea5726..03d4c7f6f5cb01fb87fe9d663065623353cb5947 100644 (file)
 #ifndef NVECTOR_H
 #define NVECTOR_H
 
-#include "defs.h"
-#include "vector3d.h"
+#include <numbers>              // for pi
+#include <utility>              // for pair
+
+#include "src/core/vector3d.h"  // for Vector3D
 
 namespace gpsbabel
 {
@@ -42,7 +44,7 @@ constexpr double WGS84_ASPECT_RATIO = 1.0 - WGS84_FLATTENING; // b/a
 constexpr double WGS84_SEMI_MINOR_AXIS_METERS = WGS84_SEMI_MAJOR_AXIS_METERS * WGS84_ASPECT_RATIO; // b
 constexpr double WGS84_ECCENTRICITY_SQUARED = 1.0 - (WGS84_ASPECT_RATIO * WGS84_ASPECT_RATIO);
 
-constexpr double kRadiansPerDegree = M_PI/180.0;
+constexpr double kRadiansPerDegree = std::numbers::pi / 180.0;
 constexpr double kDegreesPerRadian = 1.0/kRadiansPerDegree;
 
 class PVector;